package br.com.carser.business.infra;

import java.util.List;

import br.com.carser.dao.infra.BaseDAO;
import br.com.carser.dao.infra.BaseEntity;
import br.com.carser.exception.DuplicateEntityException;
import br.com.carser.exception.ParentEntityException;

/**
 * <B>Project: carser-web</B><BR>
 * 
 * Class Implementation of BaseBusiness.
 * 
 * <DL>
 * <DT><B>Created:</B>
 * <DD>Sep 20, 2011</DD></DT>
 * </DL>
 * <DL>
 * <DT><B>Last Modification:</B>
 * <DD>Sep 20, 2011</DD></DT>
 * </DL>
 * 
 * @author Caio Carleto - CarSer - Sep 20, 2011
 * @version 1.0
 */
public abstract class BaseBusinessBean<T extends BaseEntity> implements BaseBusiness<T> {
	
	/**
	 * Generated serial version id.
	 */
	private static final long serialVersionUID = -8200992381537905411L;

	@Override
	public T getById(Long id) {
		return getDAO().getById(id);
	}

	@Override
	public T saveOrUpdate(T entity) throws DuplicateEntityException {
		return getDAO().saveOrUpdate(entity);
	}

	@Override
	public void delete(T entity) throws ParentEntityException {
		getDAO().delete(entity);
	}

	@Override
	public T getByIdForUpdate(Long id) {
		return getDAO().getByIdForUpdate(id);
	}
	
	@Override
	public List<T> getAll() {
		return getDAO().getAll();
	}
	
	@Override
	public void refresh(T entity) {
		getDAO().refresh(entity);
	}
	
	/**
	 * Get DAO Object to typed class.
	 * 
	 * Inject the dao in class and return them.
	 * 
	 * @return dao.
	 */
	public abstract BaseDAO<T> getDAO();
	
}
